package com.example.demo.testdemo;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;

import java.util.ArrayList;
import java.util.List;

public class BatchProducer {
    public static void main(String[] args) throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer("producer_batch_group");
        producer.setNamesrvAddr("127.0.0.1:9876");
        producer.start();
        List<Message> list = new ArrayList<>();
        Message message1 = new Message("topic_batch","tags","key"+1,("batchMsg"+1).getBytes(RemotingHelper.DEFAULT_CHARSET));
        Message message2 = new Message("topic_batch","tags","key"+2,("batchMsg"+2).getBytes(RemotingHelper.DEFAULT_CHARSET));
        Message message3 = new Message("topic_batch","tags","key"+3,("batchMsg"+3).getBytes(RemotingHelper.DEFAULT_CHARSET));
        list.add(message1);
        list.add(message2);
        list.add(message3);
        SendResult result = producer.send(list);
        System.out.println(result.getSendStatus());
        producer.shutdown();
    }
}
